<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>魔域boss刷新提示工具</title>
    <style>
        /* CSS变量定义 - 现代化设计系统 */
        :root {
            --primary-color: #4a90e2;
            --secondary-color: #f5f7fa;
            --success-color: #7ed321;
            --warning-color: #f5a623;
            --danger-color: #d0021b;
            --text-primary: #333333;
            --text-secondary: #666666;
            --text-light: #999999;
            --border-color: #e1e5e9;
            --border-radius: 8px;
            --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            --box-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
            --transition: all 0.3s ease;
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: var(--text-primary);
        }

        .main {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            overflow: hidden;
        }

        /* 头部区域 */
        .header {
            background: var(--primary-color);
            color: white;
            padding: 20px;
            text-align: center;
        }

        .header h1 {
            margin: 0;
            font-size: 24px;
            font-weight: 600;
        }

        /* 控制面板 */
        .control-panel {
            padding: 24px;
            background: var(--secondary-color);
            border-bottom: 1px solid var(--border-color);
        }

        .control-row {
            display: flex;
            align-items: center;
            gap: 16px;
            margin-bottom: 16px;
            flex-wrap: nowrap;
        }

        .control-row:last-child {
            margin-bottom: 0;
        }

        .control-label {
            font-weight: 500;
            color: var(--text-primary);
            min-width: 60px;
        }

        .control-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        /* 现代化输入框样式 */
        input[type="text"],
        select {
            padding: 10px 12px;
            border: 2px solid var(--border-color);
            border-radius: var(--border-radius);
            font-size: 14px;
            transition: var(--transition);
            background: white;
            min-width: 200px;
        }

        input[type="text"]:focus,
        select:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
        }

        /* 现代化按钮样式 */
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: var(--border-radius);
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
            color: white;
            font-weight: 600;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #ff5252 0%, #d84315 100%);
            transform: translateY(-1px);
            box-shadow: var(--box-shadow-hover);
        }

        .btn-secondary {
            background: var(--border-color);
            color: var(--text-primary);
        }

        .btn-secondary:hover {
            background: #d1d5db;
        }

        .btn-refresh {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-refresh:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
            transform: translateY(-1px);
            box-shadow: var(--box-shadow-hover);
        }

        /* 时间输入组样式 */
        .time-input-group {
            display: flex;
            gap: 8px;
            flex: 1;
        }

        .time-input {
            flex: 1;
            min-width: 0;
        }

        .time-input-group .btn {
            flex-shrink: 0;
            min-width: 80px;
        }

        /* 按钮文本控制 */
        .btn-text-mobile {
            display: none;
        }

        .btn-text-desktop {
            display: inline;
        }

        /* 小按钮样式 */
        .btn-sm {
            padding: 6px 12px;
            font-size: 12px;
            min-width: auto;
        }

        /* 图标按钮样式 */
        .btn-icon {
            padding: 4px 8px;
            font-size: 16px;
            min-width: 32px;
            height: 32px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border: 1px solid var(--border-color);
            background: white;
            margin: 0 2px;
        }

        .btn-icon:hover {
            transform: translateY(-1px);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .btn-edit:hover {
            background: #e3f2fd;
            border-color: var(--primary-color);
        }

        .btn-delete:hover {
            background: #ffebee;
            border-color: var(--danger-color);
        }

        /* 操作按钮组 */
        .action-buttons {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        /* 记录区域 */
        .records-section {
            padding: 24px;
        }

        .section-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 16px;
            color: var(--text-primary);
        }

        #record {
            min-height: 400px;
            background: var(--secondary-color);
            border-radius: var(--border-radius);
            padding: 16px;
        }

        /* 表格样式 */
        .boss-table {
            width: 100%;
            border-collapse: collapse;
            background: white;
            border-radius: var(--border-radius);
            overflow: hidden;
            box-shadow: var(--box-shadow);
            margin-top: 16px;
        }

        .boss-table thead {
            background: var(--primary-color);
            color: white;
        }

        .boss-table th {
            padding: 16px 12px;
            text-align: left;
            font-weight: 600;
            font-size: 14px;
            border: none;
        }

        .boss-table td {
            padding: 12px;
            border-bottom: 1px solid var(--border-color);
            font-size: 14px;
            transition: var(--transition);
        }

        .boss-table tbody tr {
            transition: var(--transition);
        }

        /* 已复活BOSS的绿色背景 */
        .boss-table tbody tr.status-revived {
            background-color: #d4edda !important;
        }

        .boss-table tbody tr.status-revived:hover {
            background-color: #c3e6cb !important;
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        /* 等待复活BOSS的橙色背景 */
        .boss-table tbody tr.status-waiting {
            background-color: #fff3cd !important;
        }

        .boss-table tbody tr.status-waiting:hover {
            background-color: #ffeaa7 !important;
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        /* 默认行样式（备用） */
        .boss-table tbody tr:nth-child(even) {
            background-color: #f8f9fa;
        }

        .boss-table tbody tr:nth-child(odd) {
            background-color: white;
        }

        .boss-table tbody tr:hover {
            background-color: #e3f2fd !important;
            transform: translateY(-1px);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .boss-table tbody tr:last-child td {
            border-bottom: none;
        }

        .status-waiting {
            color: var(--warning-color);
            font-weight: 500;
        }

        .status-revived {
            color: var(--success-color);
            font-weight: 500;
        }

        .revive-time {
            color: var(--success-color);
            font-weight: 600;
        }

        .death-time {
            color: var(--text-secondary);
        }

        /* 3分钟内即将复活的BOSS高亮样式 */
        .boss-table tbody tr.highlight-soon {
            background-color: #fff3cd !important;
            border: 2px solid #ffc107 !important;
            box-shadow: 0 0 10px rgba(255, 193, 7, 0.3) !important;
        }

        .boss-table tbody tr.highlight-soon:hover {
            background-color: #fff3cd !important;
        }

        /* 确保高亮样式优先级最高 */
        .boss-table tbody tr.highlight-soon td {
            background-color: #fff3cd !important;
        }

        /* 120秒内即将复活的BOSS闪烁样式 */
        .boss-table tbody tr.highlight-critical {
            background-color: #ffebee !important;
            border: 3px solid #f44336 !important;
            box-shadow: 0 0 20px rgba(244, 67, 54, 0.5) !important;
            animation: criticalBlink 1s infinite alternate;
        }

        .boss-table tbody tr.highlight-critical:hover {
            background-color: #ffebee !important;
        }

        /* 120秒内剩余秒数的特殊样式 */
        .boss-table tbody tr.highlight-critical .remaining-seconds {
            font-weight: 900 !important;
            font-size: 18px !important;
            color: #f44336 !important;
            text-shadow: 0 0 5px rgba(244, 67, 54, 0.5);
            animation: textBlink 0.8s infinite alternate;
        }

        /* 闪烁动画 */
        @keyframes criticalBlink {
            0% {
                background-color: #ffebee !important;
                box-shadow: 0 0 20px rgba(244, 67, 54, 0.5) !important;
            }

            100% {
                background-color: #ffcdd2 !important;
                box-shadow: 0 0 30px rgba(244, 67, 54, 0.8) !important;
            }
        }

        /* 文字闪烁动画 */
        @keyframes textBlink {
            0% {
                color: #f44336 !important;
                transform: scale(1);
            }

            100% {
                color: #d32f2f !important;
                transform: scale(1.1);
            }
        }

        /* 空状态样式 */
        .empty-state {
            text-align: center;
            padding: 40px;
            color: var(--text-light);
            font-style: italic;
        }

        /* 已刷新记录弹窗 */
        #already_flush {
            position: fixed;
            top: 200px;
            right: 30px;
            z-index: 1000;
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(238, 90, 36, 0.3);
            width: 320px;
            max-height: 400px;
            overflow: hidden;
            transition: var(--transition);
            border: 3px solid #ff4757;
            display: none;
        }

        .popup-header {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            padding: 16px;
            font-weight: 700;
            text-align: center;
            font-size: 16px;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
        }

        #already_flush_record {
            max-height: 300px;
            overflow-y: auto;
            padding: 12px;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
        }

        #already_flush_record div {
            padding: 12px;
            margin-bottom: 8px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 8px;
            border-left: 4px solid #ff4757;
            font-size: 14px;
            transition: var(--transition);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        #already_flush_record div:hover {
            background: rgba(255, 255, 255, 1);
            transform: translateX(4px);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
        }

        /* 暂无记录样式 */
        .no-records {
            text-align: center;
            color: rgba(255, 255, 255, 0.8);
            font-style: italic;
            padding: 20px;
            font-size: 14px;
        }

        /* 关闭按钮 */
        #close {
            position: fixed;
            top: 60px;
            right: 30px;
            z-index: 1001;
            background: white;
            border: 2px solid var(--primary-color);
            color: var(--primary-color);
            padding: 8px 16px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 12px;
            font-weight: 500;
            transition: var(--transition);
            box-shadow: var(--box-shadow);
        }

        #close:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-1px);
        }

        /* BOSS刷新时间表按钮 */
        #boss_schedule_btn {
            position: fixed;
            top: 120px;
            right: 30px;
            z-index: 1001;
            background: white;
            border: 2px solid var(--primary-color);
            color: var(--primary-color);
            padding: 8px 12px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 20px;
            transition: var(--transition);
            box-shadow: var(--box-shadow);
        }

        #boss_schedule_btn:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-1px);
        }

        /* 音效开关按钮 */
        #audio_toggle_btn {
            position: fixed;
            top: 180px;
            right: 30px;
            z-index: 1001;
            background: white;
            border: 2px solid var(--success-color);
            color: var(--success-color);
            padding: 8px 12px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 20px;
            transition: var(--transition);
            box-shadow: var(--box-shadow);
        }

        #audio_toggle_btn:hover {
            background: var(--success-color);
            color: white;
            transform: translateY(-1px);
        }

        #audio_toggle_btn.disabled {
            border-color: var(--text-light);
            color: var(--text-light);
        }

        #audio_toggle_btn.disabled:hover {
            background: var(--text-light);
            color: white;
        }

        /* 消息提示弹出框样式 */
        .message-toast {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 9999;
            padding: 12px 24px;
            border-radius: var(--border-radius);
            color: white;
            font-size: 14px;
            font-weight: 500;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
            opacity: 0;
            transition: all 0.3s ease;
            pointer-events: none;
            min-width: 120px;
            text-align: center;
        }

        .message-toast.show {
            opacity: 1;
            transform: translate(-50%, -50%) translateY(-10px);
        }

        .message-toast.success {
            background: linear-gradient(135deg, var(--success-color) 0%, #5cb85c 100%);
        }

        .message-toast.error {
            background: linear-gradient(135deg, var(--danger-color) 0%, #c9302c 100%);
        }

        .message-toast.warning {
            background: linear-gradient(135deg, var(--warning-color) 0%, #ec971f 100%);
        }

        .message-toast.info {
            background: linear-gradient(135deg, var(--primary-color) 0%, #337ab7 100%);
        }

        /* 消息图标 */
        .message-toast .icon {
            display: inline-block;
            margin-right: 8px;
            font-size: 16px;
        }

        /* 移动端适配 */
        @media (max-width: 768px) {

            /* 在移动端隐藏表格，显示卡片 */
            .boss-table {
                display: none !important;
            }

            .boss-cards {
                display: block !important;
            }

            body {
                padding: 10px;
            }

            .control-row {
                flex-direction: column;
                align-items: stretch;
            }

            .control-label {
                min-width: auto;
                margin-bottom: 8px;
            }

            /* 时间输入组在移动端的样式 */
            .time-input-group {
                width: 100%;
            }

            .time-input {
                flex: 1;
                min-width: 0;
            }

            .time-input-group .btn {
                flex: 1;
                min-width: 0;
                max-width: 50%;
            }

            /* 移动端显示"刷新时间"，桌面端显示"刷新" */
            .btn-text-mobile {
                display: inline;
            }

            .btn-text-desktop {
                display: none;
            }

            #already_flush {
                right: 10px;
                left: 10px;
                width: auto;
            }

            #close {
                right: 10px;
            }

            #boss_schedule_btn {
                right: 10px;
            }

            #audio_toggle_btn {
                right: 10px;
            }

            #boss_schedule {
                right: 10px;
                left: 10px;
                width: auto;
            }
        }

        @media (max-width: 480px) {
            .message-toast {
                left: 20px;
                right: 20px;
                width: auto;
                transform: translateY(-50%);
                top: 50%;
            }

            .message-toast.show {
                transform: translateY(-50%) translateY(-10px);
            }

            .boss-card {
                padding: 12px;
                margin-bottom: 12px;
            }

            .card-title {
                font-size: 14px;
            }

            .card-info-row {
                font-size: 13px;
            }

            .card-remaining {
                font-size: 16px;
            }
        }

        /* BOSS刷新时间表弹窗 */
        #boss_schedule {
            position: fixed;
            top: 80px;
            right: 30px;
            z-index: 1000;
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(74, 144, 226, 0.3);
            width: 600px;
            max-height: 70vh;
            overflow: hidden;
            transition: var(--transition);
            border: 3px solid var(--primary-color);
            display: none;
        }

        #boss_schedule .popup-header {
            background: var(--primary-color);
            color: white;
            padding: 16px;
            font-weight: 700;
            text-align: center;
            font-size: 16px;
            position: relative;
        }

        #boss_schedule .close-btn {
            position: absolute;
            right: 16px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: white;
            font-size: 20px;
            cursor: pointer;
            padding: 0;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        #boss_schedule_content {
            max-height: calc(70vh - 60px);
            overflow-y: auto;
            padding: 16px;
        }

        .schedule-section {
            margin-bottom: 24px;
        }

        .schedule-section h4 {
            color: var(--primary-color);
            margin: 0 0 12px 0;
            font-size: 16px;
            border-bottom: 2px solid var(--primary-color);
            padding-bottom: 4px;
        }

        .schedule-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 16px;
            font-size: 12px;
        }

        .schedule-table th {
            background: var(--secondary-color);
            padding: 8px 6px;
            text-align: left;
            font-weight: 600;
            border: 1px solid var(--border-color);
        }

        .schedule-table td {
            padding: 6px;
            border: 1px solid var(--border-color);
            vertical-align: top;
        }

        .schedule-table tbody tr:nth-child(even) {
            background: #f8f9fa;
        }

        .quality-info {
            background: var(--secondary-color);
            padding: 12px;
            border-radius: var(--border-radius);
            font-size: 12px;
        }

        .quality-info p {
            margin: 8px 0;
        }

        /* 移动端卡片样式 */
        .boss-cards {
            display: none;
            /* 默认隐藏，在移动端显示 */
        }

        .boss-card {
            background: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            margin-bottom: 12px;
            padding: 12px;
            transition: var(--transition);
            border-left: 4px solid var(--primary-color);
        }

        .boss-card:hover {
            transform: translateY(-2px);
            box-shadow: var(--box-shadow-hover);
        }

        .boss-card.status-waiting {
            border-left-color: var(--warning-color);
            background: linear-gradient(135deg, #fff 0%, #fff9e6 100%);
        }

        .boss-card.status-revived {
            border-left-color: var(--success-color);
            background: linear-gradient(135deg, #fff 0%, #f0f9f0 100%);
        }

        .boss-card.highlight-soon {
            border: 2px solid var(--warning-color);
            box-shadow: 0 0 15px rgba(245, 166, 35, 0.3);
            background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
        }

        .boss-card.highlight-critical {
            border: 3px solid var(--danger-color);
            box-shadow: 0 0 20px rgba(208, 2, 27, 0.4);
            background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
            animation: cardBlink 1s infinite alternate;
        }

        @keyframes cardBlink {
            0% {
                box-shadow: 0 0 20px rgba(208, 2, 27, 0.4);
            }

            100% {
                box-shadow: 0 0 30px rgba(208, 2, 27, 0.7);
            }
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            padding-bottom: 6px;
            border-bottom: 1px solid var(--border-color);
        }

        .card-title {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-primary);
        }

        .card-status {
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 500;
        }

        .card-status.status-waiting {
            background: var(--warning-color);
            color: white;
        }

        .card-status.status-revived {
            background: var(--success-color);
            color: white;
        }

        .card-body {
            margin-bottom: 8px;
        }

        .card-info-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            font-size: 14px;
        }

        .card-info-row:last-child {
            margin-bottom: 0;
        }

        .card-info-label {
            color: var(--text-secondary);
            font-weight: 500;
            min-width: 60px;
        }

        .card-info-value {
            color: var(--text-primary);
            text-align: right;
            flex: 1;
        }

        .card-remaining {
            font-size: 18px;
            font-weight: 700;
            color: var(--warning-color);
            text-align: center;
            padding: 8px;
            background: rgba(245, 166, 35, 0.1);
            border-radius: var(--border-radius);
            margin: 8px 0;
        }

        .card-time-info {
            margin-top: 8px;
            padding-top: 6px;
            border-top: 1px solid rgba(0, 0, 0, 0.05);
        }

        .card-time-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 11px;
        }

        .card-time-item {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .card-time-label {
            color: var(--text-light);
            font-weight: 400;
            font-size: 10px;
        }

        .card-time-value {
            color: var(--text-secondary);
            font-size: 10px;
        }

        .boss-card.highlight-critical .card-remaining {
            color: var(--danger-color);
            background: rgba(208, 2, 27, 0.1);
            animation: textBlink 0.8s infinite alternate;
        }

        .card-actions {
            display: flex;
            justify-content: center;
            gap: 8px;
            padding-top: 8px;
            border-top: 1px solid var(--border-color);
        }

        .card-actions .btn-icon {
            padding: 8px 12px;
            font-size: 14px;
            min-width: 40px;
            height: 40px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {

            /* 在移动端隐藏表格，显示卡片 */
            .boss-table {
                display: none !important;
            }

            .boss-cards {
                display: block !important;
            }

            body {
                padding: 10px;
            }

            .control-row {
                flex-direction: column;
                align-items: stretch;
            }

            .control-label {
                min-width: auto;
            }

            #already_flush {
                right: 10px;
                left: 10px;
                width: auto;
            }

            #close {
                right: 10px;
            }

            #boss_schedule_btn {
                right: 10px;
            }

            #audio_toggle_btn {
                right: 10px;
            }

            #boss_schedule {
                right: 10px;
                left: 10px;
                width: auto;
            }
        }

        @media (max-width: 480px) {
            .boss-card {
                padding: 12px;
                margin-bottom: 12px;
            }

            .card-title {
                font-size: 14px;
            }

            .card-info-row {
                font-size: 13px;
            }

            .card-remaining {
                font-size: 16px;
            }

            .card-time-row {
                font-size: 10px;
            }

            .card-time-label {
                font-size: 9px;
            }

            .card-time-value {
                font-size: 9px;
            }
        }

        /* LayerToolObj 弹窗样式 */
        .layer-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 9998;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .layer-overlay.show {
            opacity: 1;
        }

        .layer-dialog {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.8);
            z-index: 9999;
            background: white;
            border-radius: 12px;
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
            min-width: 300px;
            max-width: 500px;
            opacity: 0;
            transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        }

        .layer-dialog.show {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }

        .layer-dialog-header {
            padding: 20px 20px 0 20px;
            text-align: center;
        }

        .layer-dialog-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--text-primary);
            margin: 0;
        }

        .layer-dialog-content {
            padding: 20px;
            text-align: center;
            font-size: 16px;
            line-height: 1.5;
            color: var(--text-secondary);
        }

        .layer-dialog-footer {
            padding: 0 20px 20px 20px;
            text-align: center;
        }

        .layer-btn {
            padding: 10px 24px;
            border: none;
            border-radius: 6px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            margin: 0 5px;
        }

        .layer-btn-primary {
            background: var(--primary-color);
            color: white;
        }

        .layer-btn-primary:hover {
            background: #357abd;
            transform: translateY(-1px);
        }

        .layer-btn-default {
            background: #f5f5f5;
            color: var(--text-primary);
            border: 1px solid var(--border-color);
        }

        .layer-btn-default:hover {
            background: #e8e8e8;
        }

        /* LayerToolObj 消息提示样式 */
        .layer-msg-toast {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 9999;
            min-width: 200px;
            max-width: 400px;
            padding: 16px 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            opacity: 0;
            transform: translate(-50%, -50%) scale(0.8);
            transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
            text-align: center;
            font-size: 16px;
            color: var(--text-primary);
        }

        .layer-msg-toast.show {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }

        .layer-msg-toast.success {
            border-left: 4px solid var(--success-color);
        }

        .layer-msg-toast.error {
            border-left: 4px solid var(--danger-color);
        }

        .layer-msg-toast.warning {
            border-left: 4px solid var(--warning-color);
        }

        .layer-msg-toast.info {
            border-left: 4px solid var(--primary-color);
        }

        /* 移动端适配 */
        @media (max-width: 768px) {
            .layer-dialog {
                left: 20px;
                right: 20px;
                width: auto;
                transform: translateY(-50%) scale(0.8);
                top: 50%;
            }

            .layer-dialog.show {
                transform: translateY(-50%) scale(1);
            }

            .layer-msg-toast {
                left: 20px;
                right: 20px;
                width: auto;
                transform: translateY(-50%) scale(0.8);
                top: 50%;
            }

            .layer-msg-toast.show {
                transform: translateY(-50%) scale(1);
            }
        }
    </style>
    <script src="./jquery-2.1.3.min.js"></script>
    <script src="./date-deal-tools.js"></script>
    <script src="./config.js"></script>
</head>

<body>

    <div class="main">
        <div class="header">
            <h1>魔域BOSS刷新提示器</h1>
        </div>

        <div class="control-panel">
            <div class="control-row">
                <span class="control-label">时间：</span>
                <div class="time-input-group">
                    <input id="time" type="text" class="time-input">
                    <button class="btn btn-refresh" onclick="reflush()">
                        <span class="btn-text-desktop">刷新</span>
                        <span class="btn-text-mobile">刷新时间</span>
                    </button>
                </div>
            </div>

            <div class="control-row">
                <div class="control-group">
                    <span class="control-label">地图：</span>
                    <select id="map">
                        <option value="bing_gong">冰宫</option>
                        <option value="mi_meng">迷梦</option>
                        <option value="yin_wu">隐雾</option>
                        <option value="ge_bi">戈壁</option>
                        <option value="hai_dao">海岛</option>
                        <option value="huo_shan">火山</option>
                    </select>
                </div>
            </div>

            <div class="control-row">
                <div class="control-group">
                    <span class="control-label">等级：</span>
                    <select id="boss_lv">
                        <option value="16" attr-date="">16</option>
                        <option value="17" attr-date="">17</option>
                        <option value="18" attr-date="">18(上品BOSS)</option>
                        <option value="20" attr-date="">20</option>
                        <option value="21" attr-date="">21</option>
                        <option value="22" attr-date="">22</option>
                        <option value="23" attr-date="">23（上品）</option>
                        <option value="26" attr-date="">26</option>
                        <option value="27" attr-date="">27</option>
                        <option value="28" attr-date="">28沼泽</option>
                        <option value="28" attr-date="">28冰妖</option>
                        <option value="29" attr-date="">29</option>
                        <option value="30" attr-date="">31</option>
                        <option value="30" attr-date="">30</option>
                        <option value="32" attr-date="">32</option>
                        <option value="33" attr-date="">33</option>
                        <option value="36" attr-date="">36</option>
                        <option value="37" attr-date="">37</option>
                        <option value="38" attr-date="">38（精品60m）</option>
                        <option value="41" attr-date="">41（精品-良品爆灵魂）</option>
                        <option value="42" attr-date="">42</option>
                        <option value="43" attr-date="">43</option>
                        <option value="46" attr-date="">46（角蜥良品）</option>
                        <option value="47" attr-date="">47（角蜥上品）</option>
                        <option value="48" attr-date="">48（角蜥精品60m）</option>
                        <option value="51" attr-date="">51</option>
                        <option value="52" attr-date="">52</option>
                        <option value="53" attr-date="">53塔亚龙（良品26m）</option>
                        <option value="53" attr-date="">53骑士亡魂</option>
                        <option value="54" attr-date="">54</option>
                        <option value="55" attr-date="">55(精品90m)</option>
                        <option value="56" attr-date="">56（良品30m/26m）</option>
                        <option value="57" attr-date="">57 (商品90m)</option>
                        <option value="58" attr-date="">58（精品90m）</option>
                        <option value="61" attr-date="">61（良品30m/良品26m）</option>
                        <option value="62" attr-date="">62（上品60m）</option>
                        <option value="63" attr-date="">63</option>
                        <option value="66" attr-date="">66</option>
                        <option value="66" attr-date="">67</option>
                        <option value="68" attr-date="">68</option>
                        <option value="71" attr-date="">71</option>
                        <option value="72" attr-date="">72</option>
                        <option value="73" attr-date="">73</option>
                        <option value="75" attr-date="">75</option>
                        <option value="75" attr-date="">76</option>
                        <option value="77" attr-date="">77</option>
                        <option value="78" attr-date="">78</option>
                        <option value="81" attr-date="">81</option>
                        <option value="82" attr-date="">82</option>
                        <option value="83" attr-date="">83</option>
                        <option value="86" attr-date="">86</option>
                        <option value="87" attr-date="">87</option>
                        <option value="88" attr-date="">88</option>
                        <option value="91" attr-date="">91</option>
                        <option value="92" attr-date="">92</option>
                        <option value="93" attr-date="">93</option>
                        <option value="96" attr-date="">96</option>
                        <option value="97" attr-date="">97</option>
                        <option value="98" attr-date="">98</option>
                    </select>
                </div>
            </div>

            <div class="control-row">
                <div class="control-group">
                    <span class="control-label">品质：</span>
                    <select id="boss_quality">
                        <option value="26">良品(26m)</option>
                        <option value="30">良品(30m)</option>
                        <option value="40">上品(40m)</option>
                        <option value="60">上品/精品(60m)</option>
                        <option value="80">特殊(80m)</option>
                        <option value="90">精品(90m)</option>
                    </select>
                </div>
            </div>

            <div class="control-row">
                <button class="btn btn-primary" id="sure" onclick="sure()">开始计时</button>
            </div>
        </div>

        <div class="records-section">
            <div class="section-title">BOSS记录</div>
            <div id="record"></div>
        </div>

        <div id="close" onclick="closeBtn(this)" data-status="0">关闭</div>
        <div id="already_flush">
            <div class="popup-header">已刷新记录</div>
            <div id="already_flush_record"></div>
        </div>

        <!-- BOSS刷新时间表 -->
        <div id="boss_schedule_btn" onclick="toggleBossSchedule()" title="BOSS刷新时间表">🗺️</div>

        <!-- 音效开关按钮 -->
        <div id="audio_toggle_btn" onclick="toggleAudio()" title="音效开关">🔊</div>
        <div id="boss_schedule">
            <div class="popup-header">
                BOSS刷新时间表
                <button class="close-btn" onclick="toggleBossSchedule()">×</button>
            </div>
            <div id="boss_schedule_content">
                <div class="schedule-section">
                    <h4>按时间顺序排列的BOSS刷新表</h4>
                    <table class="schedule-table">
                        <thead>
                            <tr>
                                <th>时间</th>
                                <th>BOSS</th>
                                <th>地图</th>
                                <th>坐标</th>
                                <th>品质</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>7:35-7:40</td>
                                <td>28级冰妖</td>
                                <td>隐雾沼泽</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:39-7:41</td>
                                <td>26级冰妖</td>
                                <td>隐雾沼泽</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:44</td>
                                <td>42级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>376-70</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:45-7:46</td>
                                <td>27级冰妖</td>
                                <td>隐雾沼泽</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:50</td>
                                <td>52级骑士</td>
                                <td>砺风戈壁</td>
                                <td>737-1072</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>7:52</td>
                                <td>31级提风</td>
                                <td>隐雾沼泽</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>7:53</td>
                                <td>17级绿精</td>
                                <td>隐雾沼泽</td>
                                <td>437-253</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:53</td>
                                <td>21级灯笼</td>
                                <td>隐雾沼泽</td>
                                <td>363-346</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:53</td>
                                <td>51级骑士</td>
                                <td>砺风戈壁</td>
                                <td>591-897</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>7:55-7:58</td>
                                <td>22-23级灯笼</td>
                                <td>隐雾沼泽</td>
                                <td>363-346</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:57</td>
                                <td>46级角蜥</td>
                                <td>砺风戈壁</td>
                                <td>1129-923</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:00</td>
                                <td>29级招魂</td>
                                <td>隐雾沼泽</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:03-8:05</td>
                                <td>30级招魂</td>
                                <td>隐雾沼泽</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:03-8:05</td>
                                <td>28级冰妖</td>
                                <td>隐雾沼泽</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:06</td>
                                <td>26级冰妖</td>
                                <td>隐雾沼泽</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:07</td>
                                <td>55级龙</td>
                                <td>砺风戈壁</td>
                                <td>722-1027</td>
                                <td>精品</td>
                            </tr>
                            <tr>
                                <td>8:08</td>
                                <td>28级招魂</td>
                                <td>隐雾沼泽</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:09-8:11</td>
                                <td>18级绿精</td>
                                <td>隐雾沼泽</td>
                                <td>633-281</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:11</td>
                                <td>53级骑士</td>
                                <td>砺风戈壁</td>
                                <td>737-1072</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:13</td>
                                <td>54级龙</td>
                                <td>砺风戈壁</td>
                                <td>690-942</td>
                                <td>精品</td>
                            </tr>
                            <tr>
                                <td>8:14</td>
                                <td>33级提风</td>
                                <td>隐雾沼泽</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:17</td>
                                <td>43级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>293-149</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:20</td>
                                <td>32级提风</td>
                                <td>隐雾沼泽</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:20</td>
                                <td>38级望齿人</td>
                                <td>砺风戈壁</td>
                                <td>353-315</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:21</td>
                                <td>68级死亡战士</td>
                                <td>迷梦沼泽</td>
                                <td>745-387</td>
                                <td>精品</td>
                            </tr>
                            <tr>
                                <td>8:23</td>
                                <td>48级角蜥</td>
                                <td>砺风戈壁</td>
                                <td>1004-797</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:26</td>
                                <td>42级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>376-70</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:35</td>
                                <td>31级提风(第二个)</td>
                                <td>隐雾沼泽</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:47</td>
                                <td>46级角蜥</td>
                                <td>砺风戈壁</td>
                                <td>1129-923</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>9:08</td>
                                <td>42级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>376-70</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>9:35</td>
                                <td>46级角蜥</td>
                                <td>砺风戈壁</td>
                                <td>1129-923</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>9:45</td>
                                <td>41级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>638-305</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>9:55</td>
                                <td>42级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>376-70</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>10:49</td>
                                <td>47级角蜥</td>
                                <td>砺风戈壁</td>
                                <td>1112-980</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>10:50</td>
                                <td>37级望齿人</td>
                                <td>砺风戈壁</td>
                                <td>451-668</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>10:52</td>
                                <td>54级巴洛骨</td>
                                <td>砺风戈壁</td>
                                <td>690-942</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:39-7:41</td>
                                <td>26级冰妖</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:45-7:46</td>
                                <td>27级冰妖</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:52</td>
                                <td>31级提风</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>7:53</td>
                                <td>17级绿精</td>
                                <td>437-253</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:53</td>
                                <td>21级灯笼</td>
                                <td>363-346</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>7:55-7:58</td>
                                <td>22-23级灯笼</td>
                                <td>363-346</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:00</td>
                                <td>29级招魂</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:03-8:05</td>
                                <td>30级招魂</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:03-8:05</td>
                                <td>28级冰妖</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:06</td>
                                <td>26级冰妖</td>
                                <td>533-506</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:08</td>
                                <td>28级招魂</td>
                                <td>566-845</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:09-8:11</td>
                                <td>18级绿精</td>
                                <td>633-281</td>
                                <td>良品</td>
                            </tr>
                            <tr>
                                <td>8:14</td>
                                <td>33级提风</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:20</td>
                                <td>32级提风</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                            <tr>
                                <td>8:35</td>
                                <td>31级提风(第二个)</td>
                                <td>728-417</td>
                                <td>上品</td>
                            </tr>
                        </tbody>
                    </table>
                </div>



                <div class="schedule-section">
                    <h4>BOSS品质说明</h4>
                    <div class="quality-info">
                        <p><strong>良品BOSS</strong>：25-35分钟刷新，灵魂爆率10/1，大爆幻魔跟魔魂晶石</p>
                        <p><strong>上品BOSS</strong>：50-70分钟刷新，灵魂爆率10/4，大爆经常出1个灵魂</p>
                        <p><strong>精品BOSS</strong>：60-90分钟刷新，灵魂爆率10/6，经常出2个灵魂跟几个装备甚至几堆金币</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    // LayerToolObj 弹窗工具对象（类似layUI）
    const LayerToolObj = {
        // 当前弹窗实例
        currentDialog: null,
        currentToast: null,

        // Alert 弹窗方法
        alert(content, title = '提示', callback = null) {
            this.closeDialog(); // 关闭现有弹窗

            // 创建遮罩层
            const overlay = document.createElement('div');
            overlay.className = 'layer-overlay';

            // 创建弹窗
            const dialog = document.createElement('div');
            dialog.className = 'layer-dialog';

            dialog.innerHTML = `
                <div class="layer-dialog-header">
                    <h3 class="layer-dialog-title">${title}</h3>
                </div>
                <div class="layer-dialog-content">
                    ${content}
                </div>
                <div class="layer-dialog-footer">
                    <button class="layer-btn layer-btn-primary" onclick="LayerToolObj.closeDialog()">确定</button>
                </div>
            `;

            // 添加到页面
            document.body.appendChild(overlay);
            document.body.appendChild(dialog);

            // 保存当前实例
            this.currentDialog = { overlay, dialog, callback };

            // 显示动画
            setTimeout(() => {
                overlay.classList.add('show');
                dialog.classList.add('show');
            }, 10);

            // 点击遮罩层关闭
            overlay.addEventListener('click', () => {
                this.closeDialog();
            });

            return this;
        },

        // 确认弹窗方法
        confirm(content, title = '确认', callback = null) {
            this.closeDialog(); // 关闭现有弹窗

            // 创建遮罩层
            const overlay = document.createElement('div');
            overlay.className = 'layer-overlay';

            // 创建弹窗
            const dialog = document.createElement('div');
            dialog.className = 'layer-dialog';

            dialog.innerHTML = `
                <div class="layer-dialog-header">
                    <h3 class="layer-dialog-title">${title}</h3>
                </div>
                <div class="layer-dialog-content">
                    ${content}
                </div>
                <div class="layer-dialog-footer">
                    <button class="layer-btn layer-btn-default" onclick="LayerToolObj.closeDialog(false)">取消</button>
                    <button class="layer-btn layer-btn-primary" onclick="LayerToolObj.closeDialog(true)">确定</button>
                </div>
            `;

            // 添加到页面
            document.body.appendChild(overlay);
            document.body.appendChild(dialog);

            // 保存当前实例
            this.currentDialog = { overlay, dialog, callback };

            // 显示动画
            setTimeout(() => {
                overlay.classList.add('show');
                dialog.classList.add('show');
            }, 10);

            // 点击遮罩层关闭
            overlay.addEventListener('click', () => {
                this.closeDialog(false);
            });

            return this;
        },

        // Msg 消息提示方法
        msg(content, type = 'info', duration = 3000) {
            this.closeToast(); // 关闭现有消息

            // 创建消息提示
            const toast = document.createElement('div');
            toast.className = `layer-msg-toast ${type}`;
            toast.innerHTML = content;

            // 添加到页面
            document.body.appendChild(toast);

            // 保存当前实例
            this.currentToast = toast;

            // 显示动画
            setTimeout(() => {
                toast.classList.add('show');
            }, 10);

            // 自动隐藏
            setTimeout(() => {
                this.closeToast();
            }, duration);

            return this;
        },

        // 成功消息
        success(content, duration = 3000) {
            return this.msg(content, 'success', duration);
        },

        // 错误消息
        error(content, duration = 3000) {
            return this.msg(content, 'error', duration);
        },

        // 警告消息
        warning(content, duration = 3000) {
            return this.msg(content, 'warning', duration);
        },

        // 信息消息
        info(content, duration = 3000) {
            return this.msg(content, 'info', duration);
        },

        // 关闭弹窗
        closeDialog(result = null) {
            if (this.currentDialog) {
                const { overlay, dialog, callback } = this.currentDialog;

                // 隐藏动画
                overlay.classList.remove('show');
                dialog.classList.remove('show');

                // 移除元素
                setTimeout(() => {
                    if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
                    if (dialog.parentNode) dialog.parentNode.removeChild(dialog);
                }, 300);

                // 执行回调
                if (callback && typeof callback === 'function') {
                    callback(result);
                }

                this.currentDialog = null;
            }
        },

        // 关闭消息提示
        closeToast() {
            if (this.currentToast) {
                const toast = this.currentToast;

                // 隐藏动画
                toast.classList.remove('show');

                // 移除元素
                setTimeout(() => {
                    if (toast.parentNode) {
                        toast.parentNode.removeChild(toast);
                    }
                }, 300);

                this.currentToast = null;
            }
        }
    };

    // 数据持久化存储管理器
    const StorageManager = {
        STORAGE_KEY: 'moyu_boss_records',
        FLUSHED_KEY: 'moyu_boss_flushed_records',

        // 保存BOSS记录
        saveBossRecord(record) {
            try {
                const records = this.getBossRecords();
                records.unshift(record);

                // 清理旧记录，只保留最近100条或最近2天的
                const cleanedRecords = this.cleanOldRecords(records);

                localStorage.setItem(this.STORAGE_KEY, JSON.stringify(cleanedRecords));
                return true;
            } catch (error) {
                console.error('保存BOSS记录失败:', error);
                return false;
            }
        },

        // 获取所有BOSS记录
        getBossRecords() {
            try {
                const data = localStorage.getItem(this.STORAGE_KEY);
                return data ? JSON.parse(data) : [];
            } catch (error) {
                console.error('读取BOSS记录失败:', error);
                return [];
            }
        },

        // 保存已刷新记录
        saveFlushedRecord(record) {
            try {
                const records = this.getFlushedRecords();
                records.unshift(record);

                // 清理旧的已刷新记录
                const cleanedRecords = this.cleanOldFlushedRecords(records);

                localStorage.setItem(this.FLUSHED_KEY, JSON.stringify(cleanedRecords));
                return true;
            } catch (error) {
                console.error('保存已刷新记录失败:', error);
                return false;
            }
        },

        // 获取已刷新记录
        getFlushedRecords() {
            try {
                const data = localStorage.getItem(this.FLUSHED_KEY);
                return data ? JSON.parse(data) : [];
            } catch (error) {
                console.error('读取已刷新记录失败:', error);
                return [];
            }
        },

        // 清空所有记录
        clearAllRecords() {
            try {
                localStorage.removeItem(this.STORAGE_KEY);
                localStorage.removeItem(this.FLUSHED_KEY);
                return true;
            } catch (error) {
                console.error('清空记录失败:', error);
                return false;
            }
        },

        // 检查存储是否可用
        isStorageAvailable() {
            try {
                const test = '__storage_test__';
                localStorage.setItem(test, test);
                localStorage.removeItem(test);
                return true;
            } catch (error) {
                return false;
            }
        },

        // 清理旧记录，只保留最近100条或最近2天的记录
        cleanOldRecords(records) {
            try {
                if (!records || records.length === 0) {
                    return records;
                }

                const now = new Date();
                const twoDaysAgo = new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000); // 2天前

                // 按时间过滤：保留最近2天的记录
                const recentRecords = records.filter(record => {
                    if (!record.createTime) return true; // 如果没有创建时间，保留记录
                    const recordTime = new Date(record.createTime);
                    return recordTime >= twoDaysAgo;
                });

                // 按数量限制：最多保留100条记录
                const limitedRecords = recentRecords.slice(0, 100);

                // 如果清理了记录，输出日志
                if (records.length > limitedRecords.length) {
                    console.log(`清理旧记录: 原有${records.length}条，保留${limitedRecords.length}条`);
                }

                return limitedRecords;
            } catch (error) {
                console.error('清理旧记录失败:', error);
                return records; // 出错时返回原记录
            }
        },

        // 清理已刷新记录的旧数据
        cleanOldFlushedRecords(records) {
            try {
                if (!records || records.length === 0) {
                    return records;
                }

                const now = new Date();
                const twoDaysAgo = new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000); // 2天前

                // 按时间过滤：保留最近2天的记录
                const recentRecords = records.filter(record => {
                    if (!record.createTime) return true; // 如果没有创建时间，保留记录
                    const recordTime = new Date(record.createTime);
                    return recordTime >= twoDaysAgo;
                });

                // 按数量限制：最多保留50条已刷新记录
                const limitedRecords = recentRecords.slice(0, 50);

                // 如果清理了记录，输出日志
                if (records.length > limitedRecords.length) {
                    console.log(`清理旧的已刷新记录: 原有${records.length}条，保留${limitedRecords.length}条`);
                }

                return limitedRecords;
            } catch (error) {
                console.error('清理旧的已刷新记录失败:', error);
                return records; // 出错时返回原记录
            }
        }
    };

    // 音效管理器
    const AudioManager = {
        audioContext: null,
        audioBuffer: null,
        isEnabled: true,
        isInitialized: false,

        // 初始化音效系统
        async init() {
            try {
                // 从localStorage读取音效设置
                const savedSettings = localStorage.getItem(CONFIG.audio.storageKey);
                if (savedSettings) {
                    const settings = JSON.parse(savedSettings);
                    this.isEnabled = settings.enabled !== false;
                }

                // 更新按钮状态
                this.updateToggleButton();

                // 如果音效被禁用，不初始化音频系统
                if (!this.isEnabled) {
                    console.log('音效已禁用');
                    return;
                }

                // 创建音频上下文
                if (window.AudioContext || window.webkitAudioContext) {
                    this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
                    console.log('音频上下文创建成功');
                } else {
                    console.warn('浏览器不支持Web Audio API，将使用HTML5 Audio');
                }

                // 生成提示音（使用Web Audio API生成简单的提示音）
                await this.generateNotificationSound();
                this.isInitialized = true;
                console.log('音效系统初始化完成');

            } catch (error) {
                console.error('音效系统初始化失败:', error);
                this.isInitialized = false;
            }
        },

        // 生成提示音
        async generateNotificationSound() {
            if (!this.audioContext) return;

            try {
                // 创建一个简单的提示音（双音调）
                const sampleRate = this.audioContext.sampleRate;
                const duration = 0.8; // 0.8秒
                const frameCount = sampleRate * duration;

                const audioBuffer = this.audioContext.createBuffer(1, frameCount, sampleRate);
                const channelData = audioBuffer.getChannelData(0);

                // 生成双音调提示音
                for (let i = 0; i < frameCount; i++) {
                    const t = i / sampleRate;
                    let frequency;

                    // 前半段高音，后半段低音
                    if (t < duration / 2) {
                        frequency = 800; // 高音
                    } else {
                        frequency = 600; // 低音
                    }

                    // 添加音量包络（淡入淡出）
                    let envelope = 1;
                    const fadeTime = 0.05; // 淡入淡出时间
                    if (t < fadeTime) {
                        envelope = t / fadeTime;
                    } else if (t > duration - fadeTime) {
                        envelope = (duration - t) / fadeTime;
                    }

                    // 生成正弦波
                    channelData[i] = Math.sin(2 * Math.PI * frequency * t) * envelope * 0.3;
                }

                this.audioBuffer = audioBuffer;
                console.log('提示音生成成功');

            } catch (error) {
                console.error('生成提示音失败:', error);
            }
        },

        // 播放提示音
        async playNotification() {
            if (!this.isEnabled) {
                console.log('音效已禁用，跳过播放');
                return;
            }

            try {
                // 如果还未初始化，先初始化
                if (!this.isInitialized) {
                    await this.init();
                }

                // 使用Web Audio API播放
                if (this.audioContext && this.audioBuffer) {
                    // 检查音频上下文状态
                    if (this.audioContext.state === 'suspended') {
                        await this.audioContext.resume();
                    }

                    const source = this.audioContext.createBufferSource();
                    const gainNode = this.audioContext.createGain();

                    source.buffer = this.audioBuffer;
                    gainNode.gain.value = CONFIG.audio.volume;

                    source.connect(gainNode);
                    gainNode.connect(this.audioContext.destination);

                    source.start();
                    console.log('音效播放成功');

                } else {
                    // 降级到HTML5 Audio（使用数据URL生成简单提示音）
                    this.playFallbackSound();
                }

            } catch (error) {
                console.error('播放音效失败:', error);
                // 尝试降级播放
                this.playFallbackSound();
            }
        },

        // 降级音效播放（使用HTML5 Audio）
        playFallbackSound() {
            try {
                // 创建一个简单的音频数据URL（440Hz正弦波）
                const audioContext = new (window.AudioContext || window.webkitAudioContext)();
                const oscillator = audioContext.createOscillator();
                const gainNode = audioContext.createGain();

                oscillator.connect(gainNode);
                gainNode.connect(audioContext.destination);

                oscillator.frequency.value = 800;
                oscillator.type = 'sine';

                gainNode.gain.setValueAtTime(0, audioContext.currentTime);
                gainNode.gain.linearRampToValueAtTime(0.3, audioContext.currentTime + 0.01);
                gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.4);

                oscillator.start(audioContext.currentTime);
                oscillator.stop(audioContext.currentTime + 0.4);

                console.log('降级音效播放成功');

            } catch (error) {
                console.error('降级音效播放也失败:', error);
            }
        },

        // 切换音效开关
        toggle() {
            this.isEnabled = !this.isEnabled;

            // 保存设置到localStorage
            const settings = { enabled: this.isEnabled };
            localStorage.setItem(CONFIG.audio.storageKey, JSON.stringify(settings));

            // 更新按钮状态
            this.updateToggleButton();

            // 如果启用音效，重新初始化
            if (this.isEnabled && !this.isInitialized) {
                this.init();
            }

            console.log('音效', this.isEnabled ? '已启用' : '已禁用');

            // 播放测试音效
            if (this.isEnabled) {
                setTimeout(() => this.playNotification(), 100);
            }
        },

        // 更新切换按钮状态
        updateToggleButton() {
            const button = document.getElementById('audio_toggle_btn');
            if (button) {
                if (this.isEnabled) {
                    button.innerHTML = '🔊';
                    button.classList.remove('disabled');
                    button.title = '音效开启 - 点击关闭';
                } else {
                    button.innerHTML = '🔇';
                    button.classList.add('disabled');
                    button.title = '音效关闭 - 点击开启';
                }
            }
        }
    };

    // 消息提示管理器
    const MessageManager = {
        // 显示消息提示
        show(message, type = 'success', duration = 2000) {
            // 移除现有的消息提示
            this.hide();

            // 创建消息元素
            const toast = document.createElement('div');
            toast.className = `message-toast ${type}`;
            toast.id = 'message-toast';

            // 设置图标
            let icon = '';
            switch (type) {
                case 'success':
                    icon = '✓';
                    break;
                case 'error':
                    icon = '✗';
                    break;
                case 'warning':
                    icon = '⚠';
                    break;
                case 'info':
                    icon = 'ℹ';
                    break;
                default:
                    icon = '✓';
            }

            // 设置内容
            toast.innerHTML = `<span class="icon">${icon}</span>${message}`;

            // 添加到页面
            document.body.appendChild(toast);

            // 触发显示动画
            setTimeout(() => {
                toast.classList.add('show');
            }, 10);

            // 自动隐藏
            setTimeout(() => {
                this.hide();
            }, duration);

            return toast;
        },

        // 隐藏消息提示
        hide() {
            const existingToast = document.getElementById('message-toast');
            if (existingToast) {
                existingToast.classList.remove('show');
                setTimeout(() => {
                    if (existingToast.parentNode) {
                        existingToast.parentNode.removeChild(existingToast);
                    }
                }, 300);
            }
        },

        // 成功消息
        success(message, duration = 2000) {
            return this.show(message, 'success', duration);
        },

        // 错误消息
        error(message, duration = 3000) {
            return this.show(message, 'error', duration);
        },

        // 警告消息
        warning(message, duration = 2500) {
            return this.show(message, 'warning', duration);
        },

        // 信息消息
        info(message, duration = 2000) {
            return this.show(message, 'info', duration);
        }
    };

    // 表格渲染器
    const TableRenderer = {
        // 格式化时间，去掉年份
        formatTimeWithoutYear(timeString) {
            if (!timeString || timeString === '未知') return timeString;
            try {
                const date = new Date(timeString);
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                const hours = String(date.getHours()).padStart(2, '0');
                const minutes = String(date.getMinutes()).padStart(2, '0');
                const seconds = String(date.getSeconds()).padStart(2, '0');
                return `${month}-${day} ${hours}:${minutes}:${seconds}`;
            } catch (error) {
                return timeString;
            }
        },

        // 计算剩余秒数
        calculateRemainingSeconds(reviveTime) {
            if (!reviveTime) return 0;
            try {
                const now = new Date();
                const revive = new Date(reviveTime);
                const diff = Math.floor((revive.getTime() - now.getTime()) / 1000);
                return Math.max(0, diff);
            } catch (error) {
                return 0;
            }
        },

        // 格式化剩余时间为分钟秒格式
        formatRemainingTime(seconds) {
            try {
                if (typeof seconds !== 'number' || isNaN(seconds)) {
                    return '0秒';
                }

                if (seconds <= 0) return '0秒';

                const minutes = Math.floor(seconds / 60);
                const remainingSeconds = seconds % 60;

                if (minutes > 0) {
                    return `${minutes}分${remainingSeconds}秒`;
                } else {
                    return `${remainingSeconds}秒`;
                }
            } catch (error) {
                console.error('时间格式化错误:', error);
                return '0秒';
            }
        },

        // 渲染BOSS记录表格和卡片
        renderBossTable(records) {
            if (!records || records.length === 0) {
                return '<div class="empty-state">暂无BOSS记录</div>';
            }

            // 过滤掉已过期的记录，只显示等待复活和已复活的记录
            const activeRecords = records.filter(record => record.status !== 'expired');

            if (activeRecords.length === 0) {
                return '<div class="empty-state">暂无有效BOSS记录</div>';
            }

            // 按剩余时间排序：倒计时少的在前面
            const currentTime = new Date().getTime();
            const sortedRecords = [...activeRecords].sort((a, b) => {
                // 已复活的BOSS排在后面
                if (a.status === 'revived' && b.status === 'waiting') return 1;
                if (a.status === 'waiting' && b.status === 'revived') return -1;

                // 等待复活的BOSS：按剩余时间升序排列（剩余时间少的在前面）
                if (a.status === 'waiting' && b.status === 'waiting') {
                    const remainingA = new Date(a.reviveTime).getTime() - currentTime;
                    const remainingB = new Date(b.reviveTime).getTime() - currentTime;
                    return remainingA - remainingB;
                }

                // 已复活的BOSS：按复活时间降序排列（最近复活的在前面）
                if (a.status === 'revived' && b.status === 'revived') {
                    const timeA = new Date(a.reviveTime).getTime();
                    const timeB = new Date(b.reviveTime).getTime();
                    return timeB - timeA;
                }

                return 0;
            });

            // 生成表格HTML（桌面端）
            const tableHTML = `
                <table class="boss-table">
                    <thead>
                        <tr>
                            <th>地图</th>
                            <th>等级</th>
                            <th>品质</th>
                            <th>死亡时间</th>
                            <th>复活时间</th>
                            <th>剩余时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        ${sortedRecords.map((record, index) => this.renderTableRow(record, index)).join('')}
                    </tbody>
                </table>
            `;

            // 生成卡片HTML（移动端）
            const cardsHTML = `
                <div class="boss-cards">
                    ${sortedRecords.map((record, index) => this.renderCard(record, index)).join('')}
                </div>
            `;

            // 返回表格和卡片的组合
            return tableHTML + cardsHTML;
        },

        // 渲染单个卡片（移动端）
        renderCard(record, index) {
            const statusClass = record.status === 'waiting' ? 'status-waiting' : 'status-revived';
            const statusText = record.status === 'waiting' ? '等待复活' : '已复活';

            // 格式化时间（去掉年份）
            const formattedDeathTime = this.formatTimeWithoutYear(record.deathTime);
            const formattedReviveTime = this.formatTimeWithoutYear(record.reviveTime);

            // 计算剩余秒数
            const remainingSeconds = this.calculateRemainingSeconds(record.reviveTime);
            const remainingDisplay = record.status === 'waiting' ? this.formatRemainingTime(remainingSeconds) : '0秒';

            // 操作按钮
            const actionButtons = `
                <div class="card-actions">
                    <button class="btn btn-icon btn-sm" onclick="restartTimer('${record.id}')" title="重新计时">🔄</button>
                    <button class="btn btn-icon btn-sm btn-edit" onclick="editRecord('${record.id}')" title="编辑">✏️</button>
                    <button class="btn btn-icon btn-sm btn-delete" onclick="deleteRecord('${record.id}')" title="删除">🗑️</button>
                </div>
            `;

            // 剩余时间显示（仅在等待复活时显示）
            const remainingTimeDisplay = record.status === 'waiting' ?
                `<div class="card-remaining">${remainingDisplay}</div>` : '';

            return `
                <div class="boss-card ${statusClass}" data-record-id="${record.id}" data-revive-time="${record.reviveTime}">
                    <div class="card-header">
                        <div class="card-title">${record.map} - ${record.level}级 - ${record.quality}</div>
                        <div class="card-status ${statusClass}">${statusText}</div>
                    </div>
                    <div class="card-body">
                        ${remainingTimeDisplay}
                        <div class="card-time-info">
                            <div class="card-time-row">
                                <span class="card-time-item">
                                    <span class="card-time-label">死亡:</span>
                                    <span class="card-time-value">${formattedDeathTime}</span>
                                </span>
                                <span class="card-time-item">
                                    <span class="card-time-label">复活:</span>
                                    <span class="card-time-value">${formattedReviveTime}</span>
                                </span>
                            </div>
                        </div>
                    </div>
                    ${actionButtons}
                </div>
            `;
        },

        // 渲染单行数据
        renderTableRow(record, index) {
            const statusClass = record.status === 'waiting' ? 'status-waiting' : 'status-revived';
            const statusText = record.status === 'waiting' ? '等待复活' : '已复活';
            const rowClass = record.status === 'waiting' ? 'status-waiting' : 'status-revived';

            // 格式化时间（去掉年份）
            const formattedDeathTime = this.formatTimeWithoutYear(record.deathTime);
            const formattedReviveTime = this.formatTimeWithoutYear(record.reviveTime);

            // 计算剩余秒数
            const remainingSeconds = this.calculateRemainingSeconds(record.reviveTime);
            const remainingDisplay = record.status === 'waiting' ? this.formatRemainingTime(remainingSeconds) : '0秒';

            // 操作按钮 - 使用图标
            const actionButtons = `
                <div class="action-buttons">
                    <button class="btn btn-icon btn-sm" onclick="restartTimer('${record.id}')" title="重新计时">🔄</button>
                    <button class="btn btn-icon btn-sm btn-edit" onclick="editRecord('${record.id}')" title="编辑">✏️</button>
                    <button class="btn btn-icon btn-sm btn-delete" onclick="deleteRecord('${record.id}')" title="删除">🗑️</button>
                </div>
            `;

            return `
                <tr class="${rowClass}" data-record-id="${record.id}" data-revive-time="${record.reviveTime}">
                    <td>${record.map}</td>
                    <td>${record.level}</td>
                    <td>${record.quality}</td>
                    <td class="death-time">${formattedDeathTime}</td>
                    <td class="revive-time">${formattedReviveTime}</td>
                    <td class="remaining-seconds">${remainingDisplay}</td>
                    <td class="${statusClass}">${statusText}</td>
                    <td>${actionButtons}</td>
                </tr>
            `;
        },

        // 从旧格式HTML中提取数据
        parseOldRecord(html) {
            const $html = $(html);
            const messageText = $html.find('am.message').text() || '';
            const reviveTimeText = $html.find('span').text() || '';

            // 解析消息格式：地图-等级-品质
            const parts = messageText.split('-');
            if (parts.length >= 3) {
                return {
                    id: Date.now().toString() + Math.random(),
                    map: parts[0],
                    level: parts[1],
                    quality: parts[2],
                    deathTime: '未知',
                    reviveTime: reviveTimeText,
                    status: 'waiting',
                    html: html
                };
            }
            return null;
        }
    };

    $(function () {
        // 检查配置是否正确加载
        console.log('CONFIG对象:', CONFIG);
        console.log('当前环境:', CONFIG ? CONFIG.env_system : 'CONFIG未定义');
        console.log('测试复活时间:', CONFIG ? CONFIG.boss_flush_time : 'CONFIG未定义');

        //dateCutSecendsNum
        var t = DateTools.getNowDate();//DateTools.getNowHour()+':'+DateTools.getNowMinute();
        // console.log(t);
        $('#time').val(t);
        // console.log(DateTools.dateAddSecendsNumTime(t, 30*60));

        // 页面加载时恢复数据
        loadStoredData();

        // 初始化音效系统
        AudioManager.init();

        setInterval(function () {
            remindMe();
        }, 1000);
    });

    // 加载存储的数据
    function loadStoredData() {
        console.log('开始加载存储数据...');

        try {
            if (!StorageManager.isStorageAvailable()) {
                console.warn('浏览器不支持localStorage，数据将无法持久化保存');
                // 即使localStorage不可用，也显示空状态
                $('#record').html('<div class="empty-state">暂无BOSS记录</div>');
                return;
            }

            console.log('localStorage可用，开始读取数据...');

            // 恢复BOSS记录 - 处理数据迁移
            let bossRecords = StorageManager.getBossRecords();
            console.log('读取到的BOSS记录:', bossRecords);

            // 检查是否需要数据迁移（从旧HTML格式转换为新的结构化格式）
            let needsMigration = false;
            const migratedRecords = [];

            bossRecords.forEach(function (record) {
                if (record.html && (!record.map || !record.level || !record.quality)) {
                    // 这是旧格式的记录，需要迁移
                    const migratedRecord = TableRenderer.parseOldRecord(record.html);
                    if (migratedRecord) {
                        migratedRecord.id = record.id || migratedRecord.id;
                        migratedRecord.createTime = record.createTime || Date.now();
                        migratedRecord.status = record.status || 'waiting';
                        migratedRecords.push(migratedRecord);
                        needsMigration = true;
                    }
                } else if (record.map && record.level && record.quality) {
                    // 这是新格式的记录，直接使用
                    migratedRecords.push(record);
                }
            });

            // 如果需要迁移，保存迁移后的数据
            if (needsMigration) {
                localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(migratedRecords));
                console.log('数据迁移完成');
            }

            // 清理旧记录（无论是否迁移都执行一次清理）
            const cleanedRecords = StorageManager.cleanOldRecords(migratedRecords);
            if (cleanedRecords.length !== migratedRecords.length) {
                localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(cleanedRecords));
                console.log('初始化时清理了旧记录');
            }

            console.log('处理后的记录:', cleanedRecords);

            // 在LOCAL环境下，调整现有记录的复活时间用于测试
            if (CONFIG.isLocalEnv()) {
                let hasAdjustments = false;
                cleanedRecords.forEach(record => {
                    if (record.status === 'waiting') {
                        // 重新计算复活时间（基于死亡时间 + boss_flush_time秒）
                        const newReviveTime = DateTools.dateAddSecendsNumTime(record.deathTime, CONFIG.boss_flush_time);
                        if (record.reviveTime !== newReviveTime) {
                            record.reviveTime = newReviveTime;
                            hasAdjustments = true;
                            console.log(`测试模式：调整${record.map}-${record.level}-${record.quality}的复活时间为${CONFIG.boss_flush_time}秒后`);
                        }
                    }
                });

                // 如果有调整，保存调整后的记录
                if (hasAdjustments) {
                    localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(cleanedRecords));
                    console.log('测试模式：已调整现有记录的复活时间');
                }
            }

            // 使用表格渲染
            const tableHtml = TableRenderer.renderBossTable(cleanedRecords);
            console.log('生成的表格HTML:', tableHtml);

            $('#record').html(tableHtml);

            // 添加表格行点击事件处理
            addTableClickHandlers();

            // 恢复已刷新记录 - 清理无效数据
            let flushedRecords = StorageManager.getFlushedRecords();

            // 过滤掉无效的记录
            const validFlushedRecords = flushedRecords.filter(function (record) {
                return record.message &&
                    record.message !== 'undefined' &&
                    record.message.trim() !== '' &&
                    record.message !== 'null';
            });

            // 清理旧的已刷新记录
            const cleanedFlushedRecords = StorageManager.cleanOldFlushedRecords(validFlushedRecords);

            // 如果记录有变化，保存清理后的记录
            if (cleanedFlushedRecords.length !== flushedRecords.length || validFlushedRecords.length !== flushedRecords.length) {
                localStorage.setItem(StorageManager.FLUSHED_KEY, JSON.stringify(cleanedFlushedRecords));
                console.log('清理无效和旧的已刷新记录');
            }

            if (cleanedFlushedRecords.length > 0) {
                let flushedHtml = '';
                cleanedFlushedRecords.forEach(function (record) {
                    flushedHtml += `<div>${record.message}</div>`;
                });
                $('#already_flush_record').html(flushedHtml);
            } else {
                // 显示暂无记录
                $('#already_flush_record').html('<div class="no-records">暂无刷新记录</div>');
            }

            console.log('数据加载完成');

        } catch (error) {
            console.error('加载数据时出错:', error);
            $('#record').html('<div class="empty-state">数据加载失败</div>');
        }
    }

    function reflush() {
        var t = DateTools.getNowDate();
        $('#time').val(t);
    }

    // 将相同地图、等级、品质的未过期记录设置为已过期
    function expireDuplicateBossRecords(map, level, quality) {
        try {
            const records = StorageManager.getBossRecords();
            let hasChanges = false;

            const updatedRecords = records.map(record => {
                // 检查是否是相同的BOSS（地图、等级、品质都相同）且状态为等待复活
                if (record.map === map &&
                    record.level === level &&
                    record.quality === quality &&
                    record.status === 'waiting') {

                    console.log(`将重复BOSS设置为已过期: ${map}-${level}-${quality}`);
                    hasChanges = true;
                    return { ...record, status: 'expired' };
                }
                return record;
            });

            // 如果有变化，保存更新后的记录
            if (hasChanges) {
                localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(updatedRecords));
                console.log('已过期重复BOSS记录');
            }
        } catch (error) {
            console.error('处理重复BOSS记录失败:', error);
        }
    }

    // 检查指定秒数内是否有相同的BOSS记录
    function isDuplicateWithinSeconds(map, level, quality, seconds) {
        try {
            const records = StorageManager.getBossRecords();
            const currentTime = Date.now();
            const timeThreshold = seconds * 1000; // 转换为毫秒

            // 检查是否有相同的BOSS在指定时间内被添加
            const duplicateFound = records.some(record => {
                // 检查是否是相同的BOSS（地图、等级、品质都相同）
                const isSameBoss = record.map === map &&
                    record.level === level &&
                    record.quality === quality;

                // 检查是否在指定时间内创建
                const isWithinTimeLimit = record.createTime &&
                    (currentTime - record.createTime) <= timeThreshold;

                // 检查状态是否为等待复活（排除已过期的记录）
                const isActive = record.status === 'waiting';

                return isSameBoss && isWithinTimeLimit && isActive;
            });

            if (duplicateFound) {
                console.log(`检测到${seconds}秒内的重复BOSS: ${map}-${level}-${quality}`);
            }

            return duplicateFound;
        } catch (error) {
            console.error('检查重复BOSS记录失败:', error);
            return false;
        }
    }

    function sure() {
        var map = $('#map option:selected').text();
        var lv = $('#boss_lv').val();
        var quality = $('#boss_quality option:selected').text();
        var quality_val = $('#boss_quality').val();

        // 检查5秒内是否有相同的BOSS记录
        if (isDuplicateWithinSeconds(map, lv, quality, 5)) {
            LayerToolObj.alert('5秒内不能重复添加相同的BOSS记录！', '警告');
            return;
        }

        var str = `<am class="message">${map}-${lv}-${quality}</am>`;
        var time = $('#time').val();

        // 使用配置文件获取BOSS复活时间
        console.log('当前环境:', CONFIG.env_system);
        console.log('原始品质值:', quality_val, '分钟');
        var reviveTimeSeconds = CONFIG.getBossReviveTime(quality_val);
        console.log('计算后的复活时间:', reviveTimeSeconds, '秒');

        // 减去提前提醒时间避免错过（仅在生产环境）
        if (!CONFIG.isLocalEnv()) {
            reviveTimeSeconds -= CONFIG.timing.earlyReminderOffset;
            console.log('生产环境：减去提前提醒时间后:', reviveTimeSeconds, '秒');
        } else {
            console.log('测试环境：不减去提前提醒时间');
        }

        var add_res_time = DateTools.dateAddSecendsNumTime(time, reviveTimeSeconds);
        var time_htm = `<span>${add_res_time}</span>`;
        var htm = `<div>${str} | ${time}  -  <b style="color: green">${time_htm}</b></div>`;

        // 先将相同地图、等级、品质的未过期记录设置为已过期
        expireDuplicateBossRecords(map, lv, quality);

        // 创建记录对象并保存到存储
        var recordData = {
            id: Date.now().toString(),
            map: map,
            level: lv,
            quality: quality,
            qualityValue: quality_val,
            deathTime: time,
            reviveTime: add_res_time,
            html: htm,
            createTime: Date.now(),
            status: 'waiting'
        };

        // 保存到localStorage
        StorageManager.saveBossRecord(recordData);

        // 重新渲染表格
        const bossRecords = StorageManager.getBossRecords();
        const tableHtml = TableRenderer.renderBossTable(bossRecords);
        $('#record').html(tableHtml);

        // 添加表格行点击事件处理
        addTableClickHandlers();
    }

    //实时读取时间
    function remindMe() {
        var t = DateTools.getNowDate();

        // 检查表格中的复活时间
        $('.boss-table tbody tr').each(function () {
            var $row = $(this);
            var reviveTime = $row.attr('data-revive-time');
            var currentTime = new Date(t);
            var bossReviveTime = new Date(reviveTime);
            var timeDiff = bossReviveTime.getTime() - currentTime.getTime();
            var minutesDiff = Math.floor(timeDiff / (1000 * 60));
            var secondsDiff = Math.floor(timeDiff / 1000);

            // 实时更新剩余秒数
            var $remainingCell = $row.find('.remaining-seconds');
            var currentStatus = $row.find('td:eq(6)').text(); // 状态列现在是第7列（索引6）

            if (currentStatus === '等待复活') {
                var remainingSeconds = Math.max(0, secondsDiff);
                $remainingCell.text(TableRenderer.formatRemainingTime(remainingSeconds));

                // 检查是否在120秒内即将复活（闪烁提示）
                if (remainingSeconds <= CONFIG.timing.criticalReminderTime && remainingSeconds > 0) {
                    // 添加120秒内闪烁样式
                    $row.removeClass('highlight-soon').addClass('highlight-critical');
                } else if (minutesDiff <= 3 && minutesDiff > 0) {
                    // 检查是否在3分钟内即将复活（普通高亮）
                    if (!$row.hasClass('highlight-dismissed')) {
                        $row.removeClass('highlight-critical').addClass('highlight-soon');
                    }
                } else if (minutesDiff <= 0) {
                    // 移除所有高亮样式（时间已过）
                    $row.removeClass('highlight-soon highlight-dismissed highlight-critical');
                }
            } else {
                // 已复活的BOSS显示0秒
                $remainingCell.text('0秒');
                // 移除所有高亮样式
                $row.removeClass('highlight-soon highlight-dismissed highlight-critical');
            }

            // 检查是否已经到了复活时间或已经过了复活时间
            if (currentTime >= bossReviveTime) {
                var recordId = $row.attr('data-record-id');

                // 检查当前状态，如果还是等待中，则触发复活
                if (currentStatus === '等待复活') {
                    // 高亮显示该行
                    $row.css({
                        'background-color': '#ffebee !important',
                        'border': '2px solid #f44336'
                    });

                    // 获取BOSS信息
                    var map = $row.find('td:eq(0)').text();
                    var level = $row.find('td:eq(1)').text();
                    var quality = $row.find('td:eq(2)').text();
                    var message = `${map}-${level}-${quality}`;

                    // 播放音效
                    AudioManager.playNotification();

                    alert('BOSS刷新了：' + message);
                    reflushed(message);

                    // 更新记录状态为"已复活"
                    updateRecordStatus(recordId, 'revived');

                    // 重新渲染表格和卡片
                    const bossRecords = StorageManager.getBossRecords();
                    const tableHtml = TableRenderer.renderBossTable(bossRecords);
                    $('#record').html(tableHtml);

                    // 添加表格行点击事件处理
                    addTableClickHandlers();
                }
            }
        });

        // 检查卡片中的复活时间（移动端）
        $('.boss-card').each(function () {
            var $card = $(this);
            var reviveTime = $card.attr('data-revive-time');
            var currentTime = new Date(t);
            var bossReviveTime = new Date(reviveTime);
            var timeDiff = bossReviveTime.getTime() - currentTime.getTime();
            var minutesDiff = Math.floor(timeDiff / (1000 * 60));
            var secondsDiff = Math.floor(timeDiff / 1000);

            // 实时更新剩余秒数
            var $remainingDiv = $card.find('.card-remaining');
            var currentStatus = $card.find('.card-status').text();

            if (currentStatus === '等待复活') {
                var remainingSeconds = Math.max(0, secondsDiff);
                $remainingDiv.text(TableRenderer.formatRemainingTime(remainingSeconds));

                // 检查是否在120秒内即将复活（闪烁提示）
                if (remainingSeconds <= CONFIG.timing.criticalReminderTime && remainingSeconds > 0) {
                    // 添加120秒内闪烁样式
                    $card.removeClass('highlight-soon').addClass('highlight-critical');
                } else if (minutesDiff <= 3 && minutesDiff > 0) {
                    // 检查是否在3分钟内即将复活（普通高亮）
                    if (!$card.hasClass('highlight-dismissed')) {
                        $card.removeClass('highlight-critical').addClass('highlight-soon');
                    }
                } else if (minutesDiff <= 0) {
                    // 移除所有高亮样式（时间已过）
                    $card.removeClass('highlight-soon highlight-dismissed highlight-critical');
                }
            } else {
                // 已复活的BOSS隐藏剩余时间
                $remainingDiv.hide();
                // 移除所有高亮样式
                $card.removeClass('highlight-soon highlight-dismissed highlight-critical');
            }

            // 检查是否已经到了复活时间或已经过了复活时间
            if (currentTime >= bossReviveTime) {
                var recordId = $card.attr('data-record-id');

                // 检查当前状态，如果还是等待中，则触发复活
                if (currentStatus === '等待复活') {
                    // 获取BOSS信息
                    var cardTitle = $card.find('.card-title').text();
                    var message = cardTitle.replace(/ - /g, '-');

                    // 播放音效
                    AudioManager.playNotification();

                    alert('BOSS刷新了：' + message);
                    reflushed(message);

                    // 更新记录状态为"已复活"
                    updateRecordStatus(recordId, 'revived');

                    // 重新渲染表格和卡片
                    const bossRecords = StorageManager.getBossRecords();
                    const tableHtml = TableRenderer.renderBossTable(bossRecords);
                    $('#record').html(tableHtml);

                    // 添加表格行点击事件处理
                    addTableClickHandlers();
                }
            }
        });

        // 兼容旧格式的记录（如果还有的话）
        $('#record div span').each(function (a, b) {
            if ($(b).html() == t) {
                $(b).parent().css({ border: '1px red solid' });
                var messageElement = $(b).parent().find('am.message');
                var message = messageElement.length > 0 ? messageElement.html() : '未知BOSS';

                // 确保message不为空或undefined
                if (!message || message === 'undefined') {
                    message = '未知BOSS';
                }

                alert('BOSS刷新了：' + message);
                reflushed(message);
                $(b).parent().remove();
            }
        });
    }

    // 更新记录状态
    function updateRecordStatus(recordId, newStatus) {
        try {
            const records = StorageManager.getBossRecords();
            const updatedRecords = records.map(record => {
                if (record.id === recordId) {
                    return { ...record, status: newStatus };
                }
                return record;
            });
            localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(updatedRecords));
        } catch (error) {
            console.error('更新记录状态失败:', error);
        }
    }

    // 添加表格行和卡片点击事件处理
    function addTableClickHandlers() {
        // 表格行点击事件
        $('.boss-table tbody tr').off('click').on('click', function () {
            var $row = $(this);

            // 如果行有高亮样式，点击后取消高亮
            if ($row.hasClass('highlight-soon')) {
                $row.removeClass('highlight-soon').addClass('highlight-dismissed');
            }
        });

        // 卡片点击事件
        $('.boss-card').off('click').on('click', function (e) {
            // 如果点击的是按钮，不处理卡片点击事件
            if ($(e.target).closest('button').length > 0) {
                return;
            }

            var $card = $(this);

            // 如果卡片有高亮样式，点击后取消高亮
            if ($card.hasClass('highlight-soon')) {
                $card.removeClass('highlight-soon').addClass('highlight-dismissed');
            }
        });
    }

    // 根据ID移除记录
    function removeRecordById(recordId) {
        try {
            const records = StorageManager.getBossRecords();
            const filteredRecords = records.filter(record => record.id !== recordId);
            localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(filteredRecords));
        } catch (error) {
            console.error('移除记录失败:', error);
        }
    }

    // 重新计时功能
    function restartTimer(recordId) {
        try {
            const records = StorageManager.getBossRecords();

            const updatedRecords = records.map(record => {
                if (record.id === recordId) {
                    // 使用原来的复活时间作为新的死亡时间（BOSS在复活时间点被击杀）
                    const newDeathTime = record.reviveTime;

                    // 使用配置文件获取BOSS复活时间
                    const reviveTimeSeconds = CONFIG.getBossReviveTime(record.qualityValue);

                    // 减去90秒避免错过（仅在生产环境）
                    let finalReviveTime = reviveTimeSeconds;
                    if (!CONFIG.isLocalEnv()) {
                        finalReviveTime -= CONFIG.timing.earlyReminderOffset;
                    }

                    // 从原复活时间开始计算新的复活时间
                    const newReviveTime = DateTools.dateAddSecendsNumTime(newDeathTime, finalReviveTime);

                    console.log(`重新计时：${record.map}-${record.level}-${record.quality}`);
                    console.log(`原复活时间：${record.reviveTime} → 新死亡时间：${newDeathTime}`);
                    console.log(`新复活时间：${newReviveTime}`);

                    return {
                        ...record,
                        deathTime: newDeathTime,
                        reviveTime: newReviveTime,
                        status: 'waiting',
                        createTime: Date.now() // 更新创建时间，避免5秒防重复限制
                    };
                }
                return record;
            });

            // 保存更新后的记录
            localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(updatedRecords));

            // 重新渲染表格
            const tableHtml = TableRenderer.renderBossTable(updatedRecords);
            $('#record').html(tableHtml);

            // 添加表格行点击事件处理
            addTableClickHandlers();

            // 显示成功提示
            const record = updatedRecords.find(r => r.id === recordId);
            if (record) {
                MessageManager.success(`重新计时成功：${record.map}-${record.level}-${record.quality}`);
            }

        } catch (error) {
            console.error('重新计时失败:', error);
            MessageManager.error('重新计时失败，请重试');
        }
    }

    // 编辑记录功能
    function editRecord(recordId) {
        try {
            const records = StorageManager.getBossRecords();
            const record = records.find(r => r.id === recordId);

            if (!record) {
                LayerToolObj.alert('记录不存在', '错误');
                return;
            }

            // 简单的编辑功能：修改死亡时间
            const newDeathTime = prompt(`编辑死亡时间\n当前：${record.deathTime}`, record.deathTime);

            if (newDeathTime && newDeathTime !== record.deathTime) {
                // 验证时间格式
                const testDate = new Date(newDeathTime);
                if (isNaN(testDate.getTime())) {
                    MessageManager.error('时间格式不正确，请使用正确的时间格式');
                    return;
                }

                // 重新计算复活时间
                const reviveTimeSeconds = CONFIG.getBossReviveTime(record.qualityValue);
                let finalReviveTime = reviveTimeSeconds;
                if (!CONFIG.isLocalEnv()) {
                    finalReviveTime -= CONFIG.timing.earlyReminderOffset;
                }

                const newReviveTime = DateTools.dateAddSecendsNumTime(newDeathTime, finalReviveTime);

                // 更新记录
                const updatedRecords = records.map(r => {
                    if (r.id === recordId) {
                        return {
                            ...r,
                            deathTime: newDeathTime,
                            reviveTime: newReviveTime
                        };
                    }
                    return r;
                });

                // 保存更新后的记录
                localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(updatedRecords));

                // 重新渲染表格
                const tableHtml = TableRenderer.renderBossTable(updatedRecords);
                $('#record').html(tableHtml);

                // 添加表格行点击事件处理
                addTableClickHandlers();

                console.log(`编辑成功：${record.map}-${record.level}-${record.quality}`);
                MessageManager.success(`编辑成功：${record.map}-${record.level}-${record.quality}`);
            }

        } catch (error) {
            console.error('编辑记录失败:', error);
            MessageManager.error('编辑失败，请重试');
        }
    }

    // 删除记录功能
    function deleteRecord(recordId) {
        try {
            const records = StorageManager.getBossRecords();
            const record = records.find(r => r.id === recordId);

            if (!record) {
                LayerToolObj.alert('记录不存在', '错误');
                return;
            }

            // 确认删除
            LayerToolObj.confirm(`确定要删除这条记录吗？<br><strong>${record.map}-${record.level}-${record.quality}</strong>`, '确认删除', (result) => {
                if (result) {
                    // 执行删除操作
                    deleteRecordConfirmed(recordId, record);
                }
            });

        } catch (error) {
            console.error('删除记录失败:', error);
            LayerToolObj.alert('删除失败，请重试', '错误');
        }
    }

    // 确认删除后的操作
    function deleteRecordConfirmed(recordId, record) {
        try {
            const records = StorageManager.getBossRecords();

            // 过滤掉要删除的记录
            const updatedRecords = records.filter(r => r.id !== recordId);

            // 保存更新后的记录
            localStorage.setItem(StorageManager.STORAGE_KEY, JSON.stringify(updatedRecords));

            // 重新渲染表格
            const tableHtml = TableRenderer.renderBossTable(updatedRecords);
            $('#record').html(tableHtml);

            // 添加表格行点击事件处理
            addTableClickHandlers();

            console.log(`删除成功：${record.map}-${record.level}-${record.quality}`);
            LayerToolObj.success(`删除成功：${record.map}-${record.level}-${record.quality}`);

        } catch (error) {
            console.error('删除记录失败:', error);
            LayerToolObj.alert('删除失败，请重试', '错误');
        }
    }

    //已刷新
    function reflushed(message) {
        // 确保message不为空或undefined
        if (!message || message === 'undefined' || message.trim() === '') {
            message = '未知BOSS';
        }

        // 保存已刷新记录到localStorage
        var flushedRecord = {
            message: message,
            time: DateTools.getNowDate(),
            timestamp: Date.now()
        };
        StorageManager.saveFlushedRecord(flushedRecord);

        var htm = `<div>${message}</div>`;
        var ahtml = $('#already_flush_record').html();

        // 如果当前显示的是"暂无记录"，则清空后再添加
        if (ahtml.includes('no-records')) {
            $('#already_flush_record').html(htm);
        } else {
            $('#already_flush_record').html('');
            $('#already_flush_record').html(htm + ahtml);
        }
    }

    //关闭
    function closeBtn(obj) {
        var attr = $(obj).attr('data-status');
        console.log(attr)
        if (attr == 0) {
            $(obj).attr('data-status', 1);
            $('#already_flush').hide();
            $(obj).html('显示');
        } else {
            $(obj).attr('data-status', 0);
            $('#already_flush').show();
            $(obj).html('关闭');
        }
    }

    // BOSS刷新时间表显示/隐藏
    function toggleBossSchedule() {
        const schedule = $('#boss_schedule');
        if (schedule.is(':visible')) {
            schedule.hide();
        } else {
            schedule.show();
        }
    }

    // 测试时间格式化功能
    function testTimeFormatting() {
        console.log('=== 时间格式化功能测试 ===');

        // 测试用例
        const testCases = [
            { input: 0, expected: '0秒' },
            { input: 30, expected: '30秒' },
            { input: 60, expected: '1分0秒' },
            { input: 90, expected: '1分30秒' },
            { input: 120, expected: '2分0秒' },
            { input: 3600, expected: '60分0秒' },
            { input: 3661, expected: '61分1秒' },
            { input: -10, expected: '0秒' },
            { input: 'invalid', expected: '0秒' },
            { input: null, expected: '0秒' },
            { input: undefined, expected: '0秒' }
        ];

        let passedTests = 0;
        let totalTests = testCases.length;

        testCases.forEach((testCase, index) => {
            const result = TableRenderer.formatRemainingTime(testCase.input);
            const passed = result === testCase.expected;

            console.log(`测试 ${index + 1}: 输入=${testCase.input}, 期望=${testCase.expected}, 实际=${result}, ${passed ? '✓ 通过' : '✗ 失败'}`);

            if (passed) {
                passedTests++;
            }
        });

        console.log(`测试结果: ${passedTests}/${totalTests} 通过`);

        if (passedTests === totalTests) {
            console.log('✓ 所有时间格式化测试通过！');
        } else {
            console.error('✗ 部分时间格式化测试失败！');
        }
    }

    // 页面加载完成后运行测试
    $(document).ready(function () {
        // 延迟执行测试，确保所有组件都已初始化
        setTimeout(function () {
            testTimeFormatting();
            console.log('=== 功能验证完成 ===');
            console.log('1. ✓ 时间格式化功能已实现');
            console.log('2. ✓ 表格视图时间显示已更新');
            console.log('3. ✓ 卡片视图时间显示已更新');
            console.log('4. ✓ 移动端卡片布局已优化（时间信息同行显示）');
            console.log('5. ✓ 实时倒计时更新机制已更新');
            console.log('6. ✓ 测试和验证功能已完成');
            console.log('7. ✓ 记录清理功能已实现（最多保留100条或2天内的记录）');
        }, 1000);
    });
</script>

</html>